var pictureIds = [];
var deleteIds = [];
function passPictureIds() {
    if(pictureIds.length != 0){
        parent.addAtlas(pictureIds);
    }
    if(deleteIds.length != 0){
        parent.deleteFromLibrary(deleteIds);
    }
    //清空数组
    pictureIds.length = 0;
    deleteIds.length = 0;
    //关闭窗口
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);

}


// item selection
$('li').click(function () {
    if(pictureIds.indexOf($(this).attr("data-id")) == -1){
        pictureIds.push($(this).attr("data-id"));
    }else {
        var index = pictureIds.indexOf($(this).attr("data-id"));
        pictureIds.splice(index,1);
    }
    $(this).toggleClass('selected');
    if ($('li.selected').length == 0)
        $('.select').removeClass('selected');
    else
        $('.select').addClass('selected');
    counter();
});


// all item selection
$('.select').click(function () {
    if ($('li.selected').length == 0) {
        $('li').addClass('selected');
        $('li').each(function(){
            pictureIds.push($(this).attr('data-id'));
        })
        $('.select').addClass('selected');
    }
    else {
        $('li').removeClass('selected');
        $('.select').removeClass('selected');
        pictureIds.length = 0;
    }
    counter();
});

// number of selected items
function counter() {
    if ($('li.selected').length > 0)
        $('.send').addClass('selected');
    else
        $('.send').removeClass('selected');
    $('.send').attr('data-counter',$('li.selected').length);
}
$('b').click(function () {
    var dataId = $(this).attr('data-id');
    deleteIds.push(dataId);
    $('li[data-id='+dataId+']').remove();
    event.stopPropagation();    //  阻止事件冒泡
});